// SPDX-FileCopyrightText: © 2024 Tenstorrent Inc.
//
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include <functional>
#include <optional>

#include "ttnn/tensor/tensor.hpp"
#include "convert_to_chw_program_factory.hpp"

#include "ttnn/device_operation.hpp"
#include "ttnn/decorators.hpp"

#include "convert_to_chw_device_operation_types.hpp"

namespace ttnn::operations::experimental::cnn::to_chw {

struct ConvertToCHWDeviceOperation {
    using operation_attributes_t = to_chw::operation_attributes_t;
    using tensor_args_t = to_chw::tensor_args_t;
    using spec_return_value_t = to_chw::spec_return_value_t;
    using tensor_return_value_t = to_chw::tensor_return_value_t;
    using program_factory_t = std::variant<program::ConvertToCHWProgramFactory>;

    static program_factory_t select_program_factory(const operation_attributes_t&, const tensor_args_t&);
    static void validate_on_program_cache_miss(const operation_attributes_t&, const tensor_args_t&);
    static void validate_on_program_cache_hit(const operation_attributes_t&, const tensor_args_t&);
    static spec_return_value_t compute_output_specs(const operation_attributes_t&, const tensor_args_t&);
    static tensor_return_value_t create_output_tensors(const operation_attributes_t&, const tensor_args_t&);
    static tt::stl::hash::hash_t compute_program_hash(const operation_attributes_t&, const tensor_args_t&);

    static std::tuple<operation_attributes_t, tensor_args_t> invoke(
        const Tensor& input,
        const std::optional<DataType>& dtype);
};

}  // namespace ttnn::operations::experimental::cnn::to_chw

namespace ttnn::prim {
constexpr auto convert_to_chw = ttnn::register_operation<
    "ttnn::prim::convert_to_chw",
    ttnn::operations::experimental::cnn::to_chw::ConvertToCHWDeviceOperation>();
}  // namespace ttnn::prim
